package com.mqb.n4;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.locks.LockSupport;

/**
 * @author mqb
 * @date 2021/5/3 15:43
 */
@Slf4j(topic = "c.MultInterruptParkDemo")
public class MultInterruptParkDemo {
    public static void main(String[] args) throws InterruptedException {
        ThreadDemo04 t4 = new ThreadDemo04();
        log.debug("start...");
        t4.start();

        Thread.sleep(5000);
        log.debug("interrupt");
        t4.interrupt();
        log.debug("t4 的打断标志位为 {}", t4.isInterrupted());

//        log.debug("unpark 第一次");
//        LockSupport.unpark(t4);
//
//        Thread.sleep(2000);
//        log.debug("unpark 第二次");
//        LockSupport.unpark(t4);

    }

    @Slf4j(topic = "c.ThreadDemo04")
    public static class ThreadDemo04 extends Thread {
        @Override
        public void run() {
            LockSupport.park();
            log.debug("本打印出现在第一个park()之后");
            LockSupport.park();
            log.debug("本打印出现在第二个park()之后");
        }
    }
}
